package 创建型.建造者;

public class BuildPeople {
    public static void main(String[] args) {
        People people = new PeopleBuilder().buildHead("一个脑袋").buildBody("好身体").buildHands("一双手").buildFeet("两只脚").build();
        System.out.println(people);
    }
}


class PeopleBuilder extends AbsBuilder {
    private People people;

    public PeopleBuilder() {
        people = new People();
    }

    @Override
    AbsBuilder buildHead(String head) {
        people.setHead(head);
        return this;
    }

    @Override
    AbsBuilder buildBody(String body) {
        people.setBody(body);
        return this;
    }

    @Override
    AbsBuilder buildHands(String hands) {
        people.setHands(hands);
        return this;
    }

    @Override
    AbsBuilder buildFeet(String feet) {
        people.setFeet(feet);
        return this;
    }

    @Override
    People build() {
        return people;
    }
}


abstract class AbsBuilder {
    /**
     * 创建头
     */
    abstract AbsBuilder buildHead(String head);

    /**
     * 创建身体
     */
    abstract AbsBuilder buildBody(String body);

    /**
     * 创建手
     */
    abstract AbsBuilder buildHands(String hands);

    /**
     * 创建脚
     */
    abstract AbsBuilder buildFeet(String feet);

    /**
     * 创建人
     */
    abstract People build();
}


/**
 * 人
 */
class People {
    private String head;
    private String body;
    private String hands;
    private String feet;

    public String getHead() {
        return head;
    }

    public People setHead(String head) {
        this.head = head;
        return this;
    }

    public String getBody() {
        return body;
    }

    public People setBody(String body) {
        this.body = body;
        return this;
    }

    public String getHands() {
        return hands;
    }

    public People setHands(String hands) {
        this.hands = hands;
        return this;
    }

    public String getFeet() {
        return feet;
    }

    public People setFeet(String feet) {
        this.feet = feet;
        return this;
    }

    @Override
    public String toString() {
        return "people{" +
                "head='" + head + '\'' +
                ", body='" + body + '\'' +
                ", hands='" + hands + '\'' +
                ", feet='" + feet + '\'' +
                '}';
    }
}
